#ifndef LOGGER_H
#define LOGGER_H

#define LOG(msg) Logger::instance()->log(msg)

#include <QObject>
#include <QFile>
#include <QFileInfo>
#include <QTextStream>
#include <QMutex>
#include <QtQml>


class Logger : public QObject {
    Q_OBJECT
    QML_ELEMENT

public:
    explicit Logger(QObject *parent = nullptr);
    ~Logger();
    static Logger* instance(QObject *parent = nullptr);      // 获取单例对象
    void setLogFile(const QString &filePath);  // 可选：指定日志文件路径

public slots:
    void log(const QString &message);  // 输出日志

private:
    QFile m_file;
    QTextStream m_stream;
    QMutex m_mutex;
};

#endif // LOGGER_H
